#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>

using namespace std;
const int N = 1e4 + 10, M = 5010;

int n, m, w;
int value[N], price[N];
int p[N];
int dp[N];


int find(int x){
    if(x != p[x]){
        p[x] = find(p[x]);
    }
    return p[x];
}

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);


    scanf("%d%d%d", &n, &m, &w);

    for(int i = 1; i <= n; i ++){
        p[i] = i;
    }

    for(int i = 1; i <= n; i ++){
        scanf("%d%d", &price[i], &value[i]);
    }

    for(int i = 0; i < m; i ++){
        int a, b;
        scanf("%d%d", &a, &b);
        int pa = find(a), pb = find(b);
        if(pa != pb){
            p[pb] = pa;
            price[pa] += price[pb];
            value[pa] += value[pb];
        }
    }

    vector<int> allPrice;
    vector<int> allValue;

    for(int i = 1; i <= n; i ++){
        if(p[i] == i){
            allPrice.push_back(price[i]);
            allValue.push_back(value[i]);
        }
    }

    for(int i = 0; i < allPrice.size(); i ++){
        cout << allPrice[i] << " ";
    }
    cout << endl << "-------------------------------------" << endl;

    for(int i = 0; i < allValue.size(); i ++){
        cout << allValue[i] << " ";
    }
    cout << endl << "-------------------------------------" << endl;
    for(int i = 0; i < allPrice.size(); i ++){
        for(int j = w; j >= 0 && j >= allPrice[i]; j--){
            dp[j] = max(dp[j], dp[j - allPrice[i]] + allValue[i]);
        }
    }

    printf("%d\n", dp[w]);

    return 0;
}